import { Column, Entity, VirtualColumn } from "typeorm";
import { BaseEntity } from "../../base/entity/base";

export type ModuleType = 'COMMENT' | 'TEAM' | 'MOTORCADE' | 'SHOP' | 'TIME' | 'MEDIA';

export const DEFAULT_MODULE_TYPES: ModuleType[] = ['COMMENT', 'TEAM', 'MOTORCADE', 'SHOP', 'TIME', 'MEDIA'];
@Entity('provider_profile', { comment: '个人信息 - 主要是名片相关配置' })
export class ProviderProfileEntity extends BaseEntity {

    @Column({ comment: '服务人员ID', nullable: false, unique: true })
    providerId: number

    @Column({ comment: '关联的运力ID', nullable: false, unique: true })
    capacityId: number

    @Column({ comment: '姓名', length: 255, nullable: false })
    name: string;

    @Column({ comment: '手机号', length: 255, nullable: false })
    phone: string;
    
    @Column({ comment: '微信号', length: 255, nullable: true })
    wechat: string;

    @Column({ comment: '性别 0-男 1-女', dict: ['男', '女'], default: 0 })
    gender: number;

    @Column({ comment: '照片', nullable: true })
    photo: string;

    @Column({ comment: '从业年限', nullable: false, default: 0 })
    experienceYears: number;

    @Column({ comment: '驾龄', nullable: false, default: 0 })
    drivingYears: number;

    @Column({ comment: '服务次数', nullable: false, default: 0 })
    serviceCount: number;

    @Column({ comment: '综合评分', type: 'decimal', precision: 10, scale: 1, default: 5 })
    comprehensiveScore: number;

    @Column({ comment: '年龄', nullable: true })
    age?: number;

    @Column({ comment: '介绍', length: 500, nullable: true })
    introduction?: string;

    @Column({ comment: '样式风格', type: 'json', nullable: true })
    style: {
        // 主色调
        primaryColor: string;
        // 次色调
        secondaryColor: string;
        // 背景色
        backgroundColor: string;
        // 背景图片
        backgroundImage: string;
        // 字体颜色
        fontColor: string;
    };

    @Column({ comment: '展示模块', type: 'simple-array', nullable: true })
    displayModule: ModuleType[] = DEFAULT_MODULE_TYPES;

    @Column({ comment: '常驻地', length: 255, nullable: true })
    residence: string;

    @Column({ comment: '服务范围', type: 'simple-array', nullable: true })
    serviceScope: string[];

    @Column({ comment: '服务内容', length: 500, nullable: true })
    serviceContent: string;

    @VirtualColumn({
        query: (alias: string) => `SELECT teamId FROM transport_capacity WHERE id = ( SELECT capacityId FROM provider_profile WHERE providerId = ${alias}.providerId ) `
    })
    teamId?: number;

    @Column({
        comment: '已缴纳质保金额度',
        type: 'decimal',
        precision: 10,
        scale: 2,
        default: 0,
    })
    depositAmount: number;
}